import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
import { timer } from 'rxjs';
import { User } from 'src/app/services/data-types/member.type';
import { MemberService } from 'src/app/services/member.service';

@Component({
  selector: 'app-member-card',
  templateUrl: './member-card.component.html',
  styleUrls: ['./member-card.component.less']
})
export class MemberCardComponent implements OnInit {
  @Input() user!: User
  @Output() openModal = new EventEmitter<void>();
  tipTitle =  ''
  showTip  =  false
  constructor(
    private memberServe: MemberService,
    private messageServer: NzMessageService,
  ) { }

  ngOnInit(): void {
  }

  onSignin(){
    this.memberServe.signin().subscribe(res=>{
      this.alertMessage('success', '签到失败')
      this.tipTitle = '积分+' + res.point
      this.showTip = true
      timer(1500).subscribe(()=>{
        this.tipTitle = ''
        this.showTip = false
      })
    },error =>{
      console.log("error",error)
      this.alertMessage('error', error.msg || '签到失败')
    })
  }
  private alertMessage( type: string, msg: string){
    this.messageServer.create(type,msg)
  }
}
